{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 224
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 122374,
     "status": "ok",
     "timestamp": 1556847890784,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "TEEIpMGJWbYq",
    "outputId": "534f48e8-57f7-43ee-ee33-2b4b0d78e472"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "E: Package 'python-software-properties' has no installation candidate\n",
      "Selecting previously unselected package google-drive-ocamlfuse.\n",
      "(Reading database ... 130812 files and directories currently installed.)\n",
      "Preparing to unpack .../google-drive-ocamlfuse_0.7.3-0ubuntu3~ubuntu18.04.1_amd64.deb ...\n",
      "Unpacking google-drive-ocamlfuse (0.7.3-0ubuntu3~ubuntu18.04.1) ...\n",
      "Setting up google-drive-ocamlfuse (0.7.3-0ubuntu3~ubuntu18.04.1) ...\n",
      "Processing triggers for man-db (2.8.3-2ubuntu0.1) ...\n",
      "Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force\n",
      "··········\n",
      "Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force\n",
      "Please enter the verification code: Access token retrieved correctly.\n"
     ]
    }
   ],
   "source": [
    "# !apt-get install -y -qq software-properties-common python-software-properties module-init-tools\n",
    "# !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null\n",
    "# !apt-get update -qq 2>&1 > /dev/null\n",
    "# !apt-get -y install -qq google-drive-ocamlfuse fuse\n",
    "# from google.colab import auth\n",
    "# auth.authenticate_user()\n",
    "# from oauth2client.client import GoogleCredentials\n",
    "# creds = GoogleCredentials.get_application_default()\n",
    "# import getpass\n",
    "# !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL\n",
    "# vcode = getpass.getpass()\n",
    "# !echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "iPgHfzlkW4Vi"
   },
   "outputs": [],
   "source": [
    "# !mkdir -p drive\n",
    "# !google-drive-ocamlfuse drive  -o nonempty"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "nFT0VSBXYQy-"
   },
   "outputs": [],
   "source": [
    "# import os\n",
    "# os.chdir('drive')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 119
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 2806,
     "status": "ok",
     "timestamp": 1556847943609,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "gFeiLczhXj7n",
    "outputId": "5fd1f5cd-d14b-4101-9b6c-4a506761e253"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'Bello Zone'\t\t\t 'MLIM7349 Case Study.pdf'\n",
      " Competitions\t\t\t 'Model Merge1.ipynb'\n",
      " CRF++-0.58.tar.gz（副本）\t 'New Recording.1.m4a'\n",
      "'Data agreement-LIU Ruilun.pdf'  'New Recording.mp3'\n",
      " Dissertation\t\t\t 'Sign up.pdf'\n",
      " lgbm_feature_selection.ipynb\t  Untitled0.ipynb\n"
     ]
    }
   ],
   "source": [
    "# !ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:10:27.238621Z",
     "start_time": "2019-05-03T04:10:27.235873Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "ibyO64gSXlSH"
   },
   "outputs": [],
   "source": [
    "# mainpath=r'./Competitions/KDD-Cup-2019-CAMMTR/Data/data_set_phase1/'\n",
    "mainpath = r'../Data/data_set_phase1/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 51
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 3313,
     "status": "ok",
     "timestamp": 1556848026129,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "LMDnpvL8X0TM",
    "outputId": "ec904558-0551-45ed-ff2f-fa1cfc1146bd"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "profiles.csv\ttest_queries.csv  train_plans.csv\n",
      "test_plans.csv\ttrain_clicks.csv  train_queries.csv\n"
     ]
    }
   ],
   "source": [
    "# !ls ./Competitions/KDD-Cup-2019-CAMMTR/Data/data_set_phase1/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:10:45.256591Z",
     "start_time": "2019-05-03T04:10:44.749093Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "5PeER2JYYDTF"
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:10:47.958105Z",
     "start_time": "2019-05-03T04:10:47.229289Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "tBw89QA0YVTJ"
   },
   "outputs": [],
   "source": [
    "train_queries = pd.read_csv(mainpath+r'train_queries.csv')\n",
    "test_queries = pd.read_csv(mainpath+r'test_queries.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:10:49.828958Z",
     "start_time": "2019-05-03T04:10:49.809545Z"
    },
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 204
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 880,
     "status": "ok",
     "timestamp": 1556848378624,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "UMH02duWYz0u",
    "outputId": "dcb70c75-7d8c-419e-fe80-69bf5debb3fc"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sid</th>\n",
       "      <th>pid</th>\n",
       "      <th>req_time</th>\n",
       "      <th>o</th>\n",
       "      <th>d</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3000821</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-11-02 17:54:30</td>\n",
       "      <td>116.29,39.97</td>\n",
       "      <td>116.32,39.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3085857</td>\n",
       "      <td>210736.0</td>\n",
       "      <td>2018-11-16 10:53:10</td>\n",
       "      <td>116.39,39.84</td>\n",
       "      <td>116.33,39.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2944522</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2018-10-06 10:33:58</td>\n",
       "      <td>116.31,39.93</td>\n",
       "      <td>116.27,40.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>559931</td>\n",
       "      <td>202427.0</td>\n",
       "      <td>2018-11-23 14:54:11</td>\n",
       "      <td>116.27,39.88</td>\n",
       "      <td>116.39,39.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2819352</td>\n",
       "      <td>172251.0</td>\n",
       "      <td>2018-10-30 11:48:41</td>\n",
       "      <td>116.34,39.96</td>\n",
       "      <td>116.37,39.86</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       sid       pid             req_time             o             d\n",
       "0  3000821       NaN  2018-11-02 17:54:30  116.29,39.97  116.32,39.96\n",
       "1  3085857  210736.0  2018-11-16 10:53:10  116.39,39.84  116.33,39.79\n",
       "2  2944522       NaN  2018-10-06 10:33:58  116.31,39.93  116.27,40.00\n",
       "3   559931  202427.0  2018-11-23 14:54:11  116.27,39.88  116.39,39.90\n",
       "4  2819352  172251.0  2018-10-30 11:48:41  116.34,39.96  116.37,39.86"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_queries.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:10:52.083523Z",
     "start_time": "2019-05-03T04:10:52.072108Z"
    },
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 204
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 731,
     "status": "ok",
     "timestamp": 1556848387853,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "GOmKK9q_Y3aa",
    "outputId": "c2df5af7-8071-4cbc-e175-df74ce635959"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sid</th>\n",
       "      <th>pid</th>\n",
       "      <th>req_time</th>\n",
       "      <th>o</th>\n",
       "      <th>d</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1126541</td>\n",
       "      <td>178395.0</td>\n",
       "      <td>2018-12-05 14:51:43</td>\n",
       "      <td>116.41,39.92</td>\n",
       "      <td>116.46,39.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>453685</td>\n",
       "      <td>179178.0</td>\n",
       "      <td>2018-12-01 12:50:33</td>\n",
       "      <td>116.39,39.90</td>\n",
       "      <td>116.41,39.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2066073</td>\n",
       "      <td>184748.0</td>\n",
       "      <td>2018-12-07 10:17:35</td>\n",
       "      <td>116.37,39.71</td>\n",
       "      <td>116.31,39.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>452746</td>\n",
       "      <td>162795.0</td>\n",
       "      <td>2018-12-01 07:52:44</td>\n",
       "      <td>116.33,39.97</td>\n",
       "      <td>116.31,39.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1431672</td>\n",
       "      <td>116384.0</td>\n",
       "      <td>2018-12-06 10:36:30</td>\n",
       "      <td>116.51,39.68</td>\n",
       "      <td>116.51,39.68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       sid       pid             req_time             o             d\n",
       "0  1126541  178395.0  2018-12-05 14:51:43  116.41,39.92  116.46,39.95\n",
       "1   453685  179178.0  2018-12-01 12:50:33  116.39,39.90  116.41,39.91\n",
       "2  2066073  184748.0  2018-12-07 10:17:35  116.37,39.71  116.31,39.89\n",
       "3   452746  162795.0  2018-12-01 07:52:44  116.33,39.97  116.31,39.98\n",
       "4  1431672  116384.0  2018-12-06 10:36:30  116.51,39.68  116.51,39.68"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_queries.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:11:01.910293Z",
     "start_time": "2019-05-03T04:11:01.704151Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "iQ6TfGTUZSPq"
   },
   "outputs": [],
   "source": [
    "train_od = train_queries[['o','d']]\n",
    "test_od = test_queries[['o','d']]\n",
    "\n",
    "od_df = pd.concat([train_od,test_od]).drop_duplicates()\n",
    "\n",
    "o_df = od_df[['o']]\n",
    "d_df = od_df[['d']]\n",
    "\n",
    "o_df.columns=['co']\n",
    "d_df.columns=['co']\n",
    "\n",
    "\n",
    "all_co = pd.concat([o_df,d_df]).drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:11:02.698343Z",
     "start_time": "2019-05-03T04:11:02.693756Z"
    },
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 865,
     "status": "ok",
     "timestamp": 1556849029922,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "-R0osv9GZebp",
    "outputId": "974ef053-8262-4534-8209-3208d1214fea"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6525, 1)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_co.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:11:05.720093Z",
     "start_time": "2019-05-03T04:11:05.671420Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "FC3BgPXoaKeg"
   },
   "outputs": [],
   "source": [
    "all_co['lng'] = all_co['co'].apply(lambda x: float(x.split(',')[0]))\n",
    "all_co['lat'] = all_co['co'].apply(lambda x: float(x.split(',')[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:11:31.472286Z",
     "start_time": "2019-05-03T04:11:31.460288Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "Tr1SbjrcahnQ"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>co</th>\n",
       "      <th>lng</th>\n",
       "      <th>lat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>116.29,39.97</td>\n",
       "      <td>116.29</td>\n",
       "      <td>39.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>116.39,39.84</td>\n",
       "      <td>116.39</td>\n",
       "      <td>39.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>116.31,39.93</td>\n",
       "      <td>116.31</td>\n",
       "      <td>39.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>116.27,39.88</td>\n",
       "      <td>116.27</td>\n",
       "      <td>39.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>116.34,39.96</td>\n",
       "      <td>116.34</td>\n",
       "      <td>39.96</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             co     lng    lat\n",
       "0  116.29,39.97  116.29  39.97\n",
       "1  116.39,39.84  116.39  39.84\n",
       "2  116.31,39.93  116.31  39.93\n",
       "3  116.27,39.88  116.27  39.88\n",
       "4  116.34,39.96  116.34  39.96"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cluster_df = all_co.copy()\n",
    "cluster_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:13:57.319011Z",
     "start_time": "2019-05-03T04:13:57.312422Z"
    },
    "colab": {},
    "colab_type": "code",
    "id": "pM93sotrapKm"
   },
   "outputs": [],
   "source": [
    "lng_mean = cluster_df['lng'].mean()\n",
    "lat_mean = cluster_df['lat'].mean()\n",
    "\n",
    "lng_mode = cluster_df['lng'].mode()[0]\n",
    "lat_mode = cluster_df['lat'].mode()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-03T04:13:58.946872Z",
     "start_time": "2019-05-03T04:13:58.929714Z"
    },
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 204
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 827,
     "status": "ok",
     "timestamp": 1556850186930,
     "user": {
      "displayName": "Alan Lau",
      "photoUrl": "https://lh3.googleusercontent.com/-ZaOsrA7oyQw/AAAAAAAAAAI/AAAAAAAAAAc/PW0qJYFKbUY/s64/photo.jpg",
      "userId": "02808478473948384287"
     },
     "user_tz": -480
    },
    "id": "ixSxY-gtdKrG",
    "outputId": "ec553cfb-14a4-42b7-e22b-78aadc8a79b1"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>co</th>\n",
       "      <th>lng</th>\n",
       "      <th>lat</th>\n",
       "      <th>main_centroid_mean_dis</th>\n",
       "      <th>main_centroid_mode_dis</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>116.29,39.97</td>\n",
       "      <td>116.29</td>\n",
       "      <td>39.97</td>\n",
       "      <td>0.173152</td>\n",
       "      <td>0.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>116.39,39.84</td>\n",
       "      <td>116.39</td>\n",
       "      <td>39.84</td>\n",
       "      <td>0.203152</td>\n",
       "      <td>0.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>116.31,39.93</td>\n",
       "      <td>116.31</td>\n",
       "      <td>39.93</td>\n",
       "      <td>0.193152</td>\n",
       "      <td>0.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>116.27,39.88</td>\n",
       "      <td>116.27</td>\n",
       "      <td>39.88</td>\n",
       "      <td>0.283152</td>\n",
       "      <td>0.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>116.34,39.96</td>\n",
       "      <td>116.34</td>\n",
       "      <td>39.96</td>\n",
       "      <td>0.133152</td>\n",
       "      <td>0.52</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             co     lng    lat  main_centroid_mean_dis  main_centroid_mode_dis\n",
       "0  116.29,39.97  116.29  39.97                0.173152                    0.56\n",
       "1  116.39,39.84  116.39  39.84                0.203152                    0.59\n",
       "2  116.31,39.93  116.31  39.93                0.193152                    0.58\n",
       "3  116.27,39.88  116.27  39.88                0.283152                    0.67\n",
       "4  116.34,39.96  116.34  39.96                0.133152                    0.52"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cluster_df['main_centroid_mean_dis']=abs(cluster_df['lng']-lng_mean)+abs(cluster_df['lat']-lat_mean)\n",
    "cluster_df['main_centroid_mode_dis']=abs(cluster_df['lng']-lng_mode)+abs(cluster_df['lat']-lat_mode)\n",
    "\n",
    "cluster_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "azkIjcNcgG9q"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Cluster.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
